/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.ddl.index.mapping;

import com.snail.server.database.engine.ddl.index.dto.IndexAddDTO;
import com.snail.server.database.engine.ddl.index.dto.IndexFieldDTO;
import com.snail.server.database.engine.ddl.index.entity.Index;
import com.snail.server.database.engine.ddl.index.entity.IndexFieldMapping;
import com.snail.server.database.engine.ddl.index.vo.IndexVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zgadmin
 * @date 2025/9/9 14:53
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface IndexMapping {

    @Mapping(target = "status", expression = "java(com.snail.starter.db.enums.EnableOrDisEnableEnum.ENABLE)")
    @Mapping(target = "tableId", source = "tableId")
    @Mapping(target = "indexId", source = "indexId")
    Index toIndex(Long tableId, Long indexId, IndexAddDTO indexAddDTO);

    ArrayList<Index> toIndexList(Long tableId, List<IndexAddDTO> indexAddList);

    @Mapping(target = "tableId", source = "tableId")
    @Mapping(target = "indexId", source = "indexId")
    @Mapping(target = "fieldId", source = "fieldId")
    IndexFieldMapping toIndexFieldMapping(Long tableId, Long indexId, Long fieldId, IndexFieldDTO indexField);

    @Mapping(target = "type", expression = "java(index.getType().getValue())")
    @Mapping(target = "status", expression = "java(index.getStatus().getValue())")
    IndexVO toIndexVO(Index index);

}